///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_MAT_DETAIL_CSIZEINFO_H_
#define _BUOLA_MAT_DETAIL_CSIZEINFO_H_

#include <buola/buola.h>

namespace buola { namespace mat { namespace detail {

//totally fixed size version
template<size_t vRows,size_t vCols>
class CSizeInfo
{
public:
    //implement the whole interface
    CSizeInfo()=default;
    CSizeInfo(size_t /*pRowsOrCols*/) {}
    CSizeInfo(size_t /*pRows*/,size_t /*pCols*/) {}

    constexpr size_t Rows() const   {   return vRows;   }
    constexpr size_t Cols() const   {   return vCols;   }
    constexpr size_t size() const   {   return vRows*vCols; }

    void Resize(size_t pRows,size_t pCols)
    {
        assert(pRows==vRows&&pCols==vCols);
    }
};

//fixed rows
template<size_t vRows>
class CSizeInfo<vRows,cDynamic>
{
public:
    //implement the whole interface
    CSizeInfo()
        :   mCols(0)
    {}
    
    CSizeInfo(size_t pCols)
        :   mCols(pCols)
    {}

    CSizeInfo(size_t pRows,size_t pCols)
        :   mCols(pCols)
    {
        assert(vRows==pRows);
    }
    
    constexpr size_t Rows() const   {   return vRows;   }
    size_t Cols() const             {   return mCols;   }
    size_t size() const   {   return vRows*mCols; }

    void Resize(size_t pRows,size_t pCols)
    {
        mCols=pCols;
        assert(pRows==vRows);
    }
    
private:
    size_t mCols;
};

//fixed columns
template<size_t vCols>
class CSizeInfo<cDynamic,vCols>
{
public:
    //implement the whole interface
    CSizeInfo()
        :   mRows(0)
    {}

    CSizeInfo(size_t pRows)
        :   mRows(pRows)
    {}

    CSizeInfo(size_t pRows,size_t pCols)
        :   mRows(pRows)
    {
        assert(vCols==pCols);
    }

    size_t Rows() const             {   return mRows;   }
    constexpr size_t Cols() const   {   return vCols;   }
    size_t size() const   {   return mRows*vCols; }

    void Resize(size_t pRows,size_t pCols)
    {
        mRows=pRows;
        assert(pCols==vCols);
    }

private:
    size_t mRows;
};

//totally dynamic size version
template<>
class CSizeInfo<cDynamic,cDynamic>
{
public:
    //implement the whole interface (that makes sense)
    CSizeInfo()
        :   mRows(0)
        ,   mCols(0)
    {}

    CSizeInfo(size_t pRows,size_t pCols)
        :   mRows(pRows)
        ,   mCols(pCols)
    {}

    size_t Rows() const  {   return mRows;   }
    size_t Cols() const  {   return mCols;   }
    size_t size() const   {   return mRows*mCols; }

    void Resize(size_t pRows,size_t pCols)
    {
        mRows=pRows;
        mCols=pCols;
    }

private:
    size_t mRows,mCols;
};

/*namespace detail*/ } /*namespace mat*/ } /*namespace buola*/ }

#endif
